﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LoginInfo.ascx.cs" Inherits="TimKen.Web.UserControls.LoginInfo" %>
<script src="../Common/Script/common.js" type="text/javascript"></script>
<link href="../Common/Style/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
    $(document).ready(function () {
        var wis = -$("#Password").width() - 3;
        $("#pd").css("left", wis + "px");

        // $("#pd").css("visibility", "visible");
        // $("#pd").css("display", ""); //.hide();
        $("#hidintcs").val('<%= Session["intcode"] != null ? Session["intcode"] : "0" %>');
        $("#UserName").val('<%= GetLangString("UserName")%>');
        $("#txt_code").val('<%= GetLangString("YourCode")%>');

        $("#UserName").focus(function () {
            $(this).attr({ style: "border-color:#FFA91A;" });
            if ($(this).val() == '<%= GetLangString("UserName")%>')
                $(this).attr("value", "");
        });
        $("#UserName").blur(function () {
            $(this).attr({ style: "border-color:#c1c1c1;" });
            if ($(this).val() == "") {
                $(this).attr("value", '<%= GetLangString("UserName")%>');
            }
        });
        $("#pd").click(function () {
            $("#pd").css("visibility", "hidden"); //.hide();
            $("#Password").focus();
        });
        $("#txt_code").focus(function () {
            $(this).attr({ style: "border-color:#FFA91A;" });
            if ($(this).val() == '<%= GetLangString("YourCode")%>')
                $(this).attr("value", "");
        });
        $("#txt_code").blur(function () {
            $(this).attr({ style: "border-color:#c1c1c1;" });
            if ($(this).val() == "") {
                $(this).attr("value", '<%= GetLangString("YourCode")%>');
            }
        });

        $("#Password").focus(function () {
            $("#pd").css("visibility", "hidden"); //.hide();
        });
        $("#Password").blur(function () {
            if ($("#Password").val() == "")
                $("#pd").css("visibility", "visible"); //.show();
        });
        var intclick = parseInt($("#hidintcs").val());
        if (intclick >= 3) {
            $("#span_yzm").show();
        }
        else {
            $("#span_yzm").hide();
        }
        //响应回车时间
        $(document).keyup(function (e) {
            if (e.keyCode === 13) {
                userlogin();
            }
        });
    });
    function userlogin() {
        var intclick = parseInt($("#hidintcs").val());
        if (intclick >=3) {
            $("#span_yzm").show();
        }
        else {
            $("#span_yzm").hide();
        }
        $("#hidintcs").val(intclick + 1);
        if (document.getElementById("UserName").value == "" || document.getElementById("UserName").value == '<%=GetLangString("UserName")%>') {
            alert('<%= GetLangString("x_UserNameNotAllowBlank")%>');
            return false;
        }
        else if (document.getElementById("Password").value == "") {
            alert('<%= GetLangString("x_PasswordNotAllowBlank")%>');
            return false;
        }
        else {
            if (intclick >= 3) {
                if ($("#txt_code").val().length <= 0 || $("#txt_code").val() == "" || $("#txt_code").val() == '<%=GetLangString("YourCode")%>') {
                    alert('<%= GetLangString("x_CodeNotAllowBlank")%>');
                    return false;
                } else {
                    ChangeChecked();
                    jqGetUrl(intclick);
                    //document.location = '/User/Login.aspx?UserName=' + document.getElementById("UserName").value + '&Password=' + document.getElementById("Password").value + '&TxtCode=' + $("#txt_code").val() + '&intcode=' + intclick;
                }
            } else {
                ChangeChecked();
                jqGetUrl(intclick);
                //document.location = '/User/Login.aspx?UserName=' + document.getElementById("UserName").value + '&Password=' + document.getElementById("Password").value + '&TxtCode=' + $("#txt_code").val() + '&intcode=' + intclick;
            }
        }
        function jqGetUrl(intclick) {
            $.ajax({
                type: "Post",
                url: "/User/UserLogin.aspx",
                data: "UserName=" + document.getElementById("UserName").value + "&Password=" + document.getElementById("Password").value + "&TxtCode=" + $("#txt_code").val() + "&intcode=" + intclick,
                dataType: "text",
                success: function (data) { 
                    if (data == "1")
                        window.location = '<%=Request.RawUrl %>'; // "/Index.aspx";
                    else if (data == "2")
                        window.location = "/User/UserAccountEdit.aspx";
                    else if (data == "3")
                        window.location = "/User/UserAccountEdit.aspx?type=1";
                    else if (data == "4")
                        window.location = '<%=Request.QueryString["reurl"] %>';
                    else if (data == "5")
                        window.location = "/User/UserAccountEdit.aspx?type=1";
                    else if (data == "6")
                        window.location = "/User/AfterRegister.aspx?action=1";
                    else if (data == "7") {
                        alert('<%=GetLangString("x_CodeNotAllowBlank") %>');
                        //                        window.location = "/Index.aspx";
                    }
                    else if (data == "0") {
                        alert('<%=GetLangString("ErrorLogin") %>');
                        //                        window.location = "/Index.aspx"; 
                    }
                    //alert(data);
                    //  window.location = "/Index.aspx";
                },
                error: function () {
                    alert('<%= GetLangString("ErrorLogin") %>');
                    // window.location="/Index.aspx"; 
                }
            });
        }
        function ChangeChecked() {
            var cb = document.getElementById('cbSaveUserName');
            if (cb.checked) {
                setcookie("username", document.getElementById('UserName').value, 3000000);
            } else {
                setcookie("username", "", 3000000);
            }
        }
    }
    function setNameValue() {
        var cb = document.getElementById('cbSaveUserName');
        if (cb) {
            var username = getcookie('username');
            if (username == "" || username == null || username == ";") {
                cb.checked = false;
            } else {
                document.getElementById("UserName").value = getcookie('username');
                //document.getElementById("Password").value=
                cb.checked = true;
            }
        }
    }
    function loginKeyDown(evt) {
        if (Util.getCode(evt) === "13") {
            userlogin();
        }
    }
    function getimgcode() {
        var getimagecode = document.getElementById("getcode");
        getimagecode.src = "../ashx/ValidateCode.ashx?stamp=" + Math.random();
    }
    function addCookie(objValue) {
        // document.location = '/User/Login.aspx?language=' + objValue;
        $.ajax({
            type: "Post",
            url: "/User/Login.aspx",
            data: "language=" + objValue,
            dataType: "text",
            success: function (data) {
                window.location = '<%=Request.RawUrl %>'; // "/Index.aspx"; 
            },
            error: function () {
                window.location = "/Index.aspx";
            }
        });
    } 


</script>
<style type="text/css">
    .btndisplay
    {
        display: none;
    }
    *html #pd
    {
        border: none;
        font-size: 12px;
        color: #acacac;
        position: relative;
        top: -27px;
        margin-right: -35px;
        font-family: @宋体;
    }
    #pd
    {
        border: none;
        font-size: 12px;
        color: #acacac;
        position: relative;
        top: 1px;
        margin-right: -35px;
        font-family: @宋体;
    }
    .spanwhith
    {
        width: 80px;
    }
</style>
<%if (CurrentUserName == null)
  {%>
<ul class="topL floatleft">
    <%=GetLangString("WelcomeInfo") %>
</ul>
<ul class="topC floatleft">
    <input type="hidden" id="hidintcs" value="0" />
    <input class="topCin" id="UserName" type="text" />
    <input class="topCin" id="Password" type="password" />
    <label id="pd">
        <%=GetLangString("Password")%>
    </label>
    <span id="span_yzm" class="btndisplay">
        <input class="topCint" id="txt_code" type="text" />
        <img src="../ashx/ValidateCode.ashx" id="getcode" alt="" onclick="getimgcode()" />
    </span>
    <% if (LanguageID == 1)
       {%>
    <span onclick="return userlogin();">
        <img id="imgLogin" src="../Common/Image/iconbtnbg/denglubtn.gif" height="24" width="61" />
    </span><a href="../User/Register.aspx">
        <img src="../Common/Image/iconbtnbg/zhucebtn.gif" width="61" height="24" border="none"></a>
    <%}
       else
       { 
    %>
    <span onclick="return userlogin();">
        <%--  <input id="engLogin" type="image" onclick="return userlogin();" src="../Common/Image/iconbtnbg_en/denglubtn.gif"
        id="Image3" width="61" height="24" />--%>
        <img id="Image3" src="../Common/Image/iconbtnbg_en/denglubtn.gif" height="24" width="61" />
    </span><a href="../User/Register.aspx">
        <img src="../Common/Image/iconbtnbg_en/zhucebtn.gif" width="61" height="24" border="none"></a>
    <%} %>
    <input type="checkbox" name="cbSaveUserName" id="cbSaveUserName" class="space3"><%=GetLangString("SaveUserName")%>
    | <a href="../User/GetMyPassword.aspx" class="text">
        <%=GetLangString("ForgotPassword") %></a>
</ul>
<% }
  else
  {%>
<ul class="topL floatleft">
    您好，<span><%=CurrentUserName.ToString()%></span> <a href="../User/Logout.aspx">
        <%=GetLangString("Logout") %></a>|
    <%--<a href="#">更换用户</a>--%>
    <a href="../PromotionProducts.aspx">
        <%=GetLangString("ForYou") %></a> <a href="../order/MyOders.aspx">
            <%=GetLangString("MyOrder") %></a> <a href="../Shop/ShopProJect.aspx">
                <%=GetLangString("ShoppingCart") %><span  style="color:#eb6100;">(<%=this.ShopCart.GetItems!=null?this.ShopCart.GetItems.Count:0 %>)</span></a> <a href="../User/Edit.aspx">
                    <%=GetLangString("Profile") %></a>
</ul>
<%}%>
<ul class="topR floatright">
    <a onclick="addCookie('zh-CN')" href="#">中文</a>|<a onclick="addCookie('en-US')" href="#">English</a>
</ul>
